package com.wmwj.hxlj.mapper;

import com.wmwj.hxlj.entity.Follow;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface FollowerMapper {

    /**
     * 根据关注者id和被关注者id查询关注关系
     * @param followeeId
     * @param followerId
     * @return
     */
    @Select("SELECT * FROM follow WHERE followee_id = #{followeeId} AND follower_id = #{followerId}")
    Follow findByIdAndFollow(Long followeeId, Long followerId);

    /**
     * 插入关注关系
     * @param followeeId
     * @param followerId
     * @return 插入成功返回1，否则返回0
     */
    @Insert("INSERT INTO follow(followee_id, follower_id) VALUES(#{followeeId}, #{followerId})")
    int insert(Long followeeId, Long followerId);

    /**
     * 更新关注关系状态(软添加）
     * @param followeeId
     * @param followerId
     * @return 更新成功返回1，否则返回0
     */
    @Update("UPDATE follow SET status = 1 WHERE followee_id = #{followeeId} AND follower_id = #{followerId}")
    int insertStatus(Long followeeId, Long followerId);

    /**
     * 更新关注关系状态（软删除）
     * @param followeeId
     * @param followerId
     * @return 更新成功返回1，否则返回0
     */
    @Update("UPDATE follow SET status = 0 WHERE followee_id = #{followeeId} AND follower_id = #{followerId}")
    int deleteStatus(Long followeeId, Long followerId);
}
